﻿Imports System.Runtime.InteropServices
Imports System.Text

Friend NotInheritable Class NativeMethods
    ' Methods
    Private Sub New()
    End Sub

    Friend Shared Function HIWORD(ByVal dwValue As Integer) As Short
        Return CShort(((dwValue >> &H10) And &HFFFF))
    End Function

    <DllImport("kernel32")> _
    Friend Shared Function IsWow64Process(ByVal hProcess As IntPtr, <Out()> ByRef pIsWow64 As Boolean) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    Friend Shared Function LOWORD(ByVal dwValue As Integer) As Short
        Return CShort((dwValue And &HFFFF))
    End Function

    <DllImport("advapi32")> _
    Friend Shared Function RegCloseKey(ByVal hKey As UIntPtr) As UInt32
    End Function

    <DllImport("advapi32.dll")> _
    Friend Shared Function RegEnumValue(ByVal hkey As UIntPtr, ByVal index As UInt32, ByVal lpValueName As StringBuilder, ByRef lpcbValueName As UInt32, ByVal reserved As IntPtr, ByVal lpType As IntPtr, ByVal lpData As IntPtr, ByVal lpcbData As IntPtr) As Integer
    End Function

    <DllImport("advapi32")> _
    Friend Shared Function RegOpenKeyEx(ByVal hKey As UIntPtr, ByVal lpSubKey As String, ByVal ulOptions As Integer, ByVal samDesired As Integer, <Out()> ByRef phkResult As UIntPtr) As Integer
    End Function

    <DllImport("advapi32.dll")> _
    Friend Shared Function RegQueryInfoKey(ByVal hkey As UIntPtr, ByVal lpClass As Byte(), ByVal lpcbClass As IntPtr, ByVal lpReserved As IntPtr, <Out()> ByRef lpcSubKeys As UInt32, ByVal lpcbMaxSubKeyLen As IntPtr, ByVal lpcbMaxClassLen As IntPtr, <Out()> ByRef lpcValues As UInt32, ByVal lpcbMaxValueNameLen As IntPtr, ByVal lpcbMaxValueLen As IntPtr, ByVal lpcbSecurityDescriptor As IntPtr, ByVal lpftLastWriteTime As IntPtr) As Integer
    End Function

    <DllImport("advapi32")> _
    Friend Shared Function RegQueryValueEx(ByVal hKey As UIntPtr, ByVal lpValueName As String, ByVal lpReserved As UInt32, ByRef lpType As UInt32, ByVal lpData As IntPtr, ByRef lpchData As Integer) As Integer
    End Function

    Friend Shared Function SQL_SUCCEEDED(ByVal rc As Short) As Boolean
        Return ((rc And -2) = 0)
    End Function

    <DllImport("odbc32.dll")> _
    Friend Shared Function SQLAllocConnect(ByVal EnvironmentHandle As IntPtr, <Out()> ByRef ConnectionHandle As IntPtr) As Short
    End Function

    <DllImport("odbc32.dll")> _
    Friend Shared Function SQLAllocEnv(<Out()> ByRef EnvironmentHandle As IntPtr) As Short
    End Function

    <DllImport("odbc32.dll")> _
    Friend Shared Function SQLDisconnect(ByVal ConnectionHandle As IntPtr) As Short
    End Function

    <DllImport("odbc32.dll", EntryPoint:="SQLDriverConnectW", CharSet:=CharSet.Unicode)> _
    Friend Shared Function SQLDriverConnect(ByVal hdbc As IntPtr, ByVal hwnd As IntPtr, ByVal szConnStrIn As String, ByVal cbConnStrIn As Short, ByVal szConnStrOut As StringBuilder, ByVal cbConnStrOutMax As Short, <Out()> ByRef pcbConnStrOut As Short, ByVal fDriverCompletion As UInt16) As Short
    End Function

    <DllImport("odbc32.dll")> _
    Friend Shared Function SQLFreeConnect(ByVal ConnectionHandle As IntPtr) As Short
    End Function

    <DllImport("odbc32.dll")> _
    Friend Shared Function SQLFreeEnv(ByVal EnvironmentHandle As IntPtr) As Short
    End Function

    <DllImport("odbccp32.dll", CharSet:=CharSet.Unicode)> _
    Friend Shared Function SQLGetInstalledDrivers(ByVal lpszBuf As Char(), ByVal cbBufMax As Integer, ByRef pcbBufOut As Integer) As Boolean
    End Function

    <DllImport("odbccp32.dll", CharSet:=CharSet.Unicode)> _
    Friend Shared Function SQLGetPrivateProfileString(ByVal lpszSection As String, ByVal lpszEntry As String, ByVal lpszDefault As String, ByVal RetBuffer As StringBuilder, ByVal cbRetBuffer As Integer, ByVal lpszFilename As String) As Integer
    End Function


    ' Fields
    Friend Const CLSCTX_INPROC_SERVER As Integer = 1
    Friend Shared CLSID_DataLinks As Guid = New Guid("2206CDB2-19C1-11d1-89E0-00C04FD7A829")
    Friend Shared CLSID_MSDASQL_ENUMERATOR As Guid = New Guid("C8B522CD-5CF3-11ce-ADE5-00AA0044773D")
    Friend Shared CLSID_OLEDB_ENUMERATOR As Guid = New Guid("C8B522D0-5CF3-11ce-ADE5-00AA0044773D")
    Friend Const DB_E_CANCELED As Integer = -2147217842
    Friend Const DBPROMPTOPTIONS_DISABLE_PROVIDER_SELECTION As Integer = &H10
    Friend Const DBPROMPTOPTIONS_PROPERTYSHEET As Integer = 2
    Friend Const DBSOURCETYPE_DATASOURCE_MDP As Integer = 3
    Friend Const DBSOURCETYPE_DATASOURCE_TDP As Integer = 1
    Friend Const HELPINFO_WINDOW As Integer = 1
    Friend Shared ReadOnly HKEY_LOCAL_MACHINE As UIntPtr = New UIntPtr(2147483650)
    Friend Shared IID_IUnknown As Guid = New Guid("00000000-0000-0000-c000-000000000046")
    Friend Const KEY_QUERY_VALUE As Integer = 1
    Friend Const KEY_WOW64_32KEY As Integer = &H200
    Friend Const KEY_WOW64_64KEY As Integer = &H100
    Friend Const SC_CONTEXTHELP As Integer = &HF180
    Friend Const SQL_DRIVER_PROMPT As UInt16 = 2
    Friend Const SQL_NO_DATA As Short = 100
    Friend Const WM_CONTEXTMENU As Integer = &H7B
    Friend Const WM_HELP As Integer = &H53
    Friend Const WM_SETFOCUS As Integer = 7
    Friend Const WM_SYSCOMMAND As Integer = &H112

    ' Nested Types
    <StructLayout(LayoutKind.Sequential)> _
    Friend Class HELPINFO
        Public cbSize As Integer = Marshal.SizeOf(GetType(HELPINFO))
        Public iContextType As Integer
        Public iCtrlId As Integer
        Public hItemHandle As IntPtr
        Public dwContextId As Integer
        Public MousePos As POINT
    End Class

    <ComImport(), Guid("2206CCB1-19C1-11D1-89E0-00C04FD7A829"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
    Friend Interface IDataInitialize
        Sub GetDataSource(<[In](), MarshalAs(UnmanagedType.IUnknown)> ByVal pUnkOuter As Object, <[In](), MarshalAs(UnmanagedType.U4)> ByVal dwClsCtx As Integer, <[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pwszInitializationString As String, <[In]()> ByRef riid As Guid, <[In](), Out(), MarshalAs(UnmanagedType.IUnknown)> ByRef ppDataSource As Object)
        Sub GetInitializationString(<[In](), MarshalAs(UnmanagedType.IUnknown)> ByVal pDataSource As Object, <[In](), MarshalAs(UnmanagedType.I1)> ByVal fIncludePassword As Boolean, <Out(), MarshalAs(UnmanagedType.LPWStr)> ByRef ppwszInitString As String)
        Sub Unused_CreateDBInstance()
        Sub Unused_CreateDBInstanceEx()
        Sub Unused_LoadStringFromStorage()
        Sub Unused_WriteStringToStorage()
    End Interface

    <ComImport(), Guid("2206CCB0-19C1-11D1-89E0-00C04FD7A829"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
    Friend Interface IDBPromptInitialize
        Sub PromptDataSource(<[In](), MarshalAs(UnmanagedType.IUnknown)> ByVal pUnkOuter As Object, <[In]()> ByVal hwndParent As IntPtr, <[In](), MarshalAs(UnmanagedType.U4)> ByVal dwPromptOptions As Integer, <[In](), MarshalAs(UnmanagedType.U4)> ByVal cSourceTypeFilter As Integer, <[In]()> ByVal rgSourceTypeFilter As IntPtr, <[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pwszszzProviderFilter As String, <[In]()> ByRef riid As Guid, <[In](), Out(), MarshalAs(UnmanagedType.IUnknown)> ByRef ppDataSource As Object)
        Sub Unused_PromptFileName()
    End Interface

    <StructLayout(LayoutKind.Sequential)> _
    Friend Structure POINT
        Public x As Integer
        Public y As Integer
    End Structure
End Class


